<template>
	<view class='search-box'>
		<view class='search-content'>
			<view class='search-input'>
				<image class='icon' src='https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/search.png'></image>
				<input v-model='searchVal' placeholder="输入宠物认证编号"/>
				<view class='btn' @click='handleSearch'>查询</view>
			</view>
		</view>
		
		<view v-if='isNull' class='data-null' style='margin-top: 200rpx;'>
			<image class='img' src='https://qiyeji.oss-cn-beijing.aliyuncs.com/202501111712257859.png'></image>
			<view class='text'>暂无信息</view>
		</view>
		
		<view class='info-box' v-if='cargoDetail.id && !isNull' >
			<view class="head">
				<view class="box">
					<view class="user">
						<image class="picture" :src="cargoDetail.picture" mode="aspectFill"></image>
						<view class="user-content">
							<view class="user-head">
								<view class="user-head-name text-cut">
									{{cargoDetail.name || '--'}}
								</view>
								<image class='status' src='https://qiyeji.oss-cn-beijing.aliyuncs.com/202501111739330807.png'></image>
							</view>
							<view class="user-id">
								ID：{{cargoDetail.cargoNo || '--'}}
							</view>
						</view>
					</view>
					<view class="box-tab">
						<view class="box-tab-item">
							<view class="box-tab-value">{{cargoDetail.age || '--'}}</view>
							<view class="box-tab-key">年龄</view>
						</view>
						<view class="box-tab-item">
							<view class="box-tab-value">{{cargoDetail.type2Str || '--'}}</view>
							<view class="box-tab-key">品种</view>
						</view>
						<view class="box-tab-item">
							<view class="box-tab-value">
								{{cargoDetail.sex == 'Male'? '男孩' : cargoDetail.sex == 'Female' ? '女孩' : '未知'}}
							</view>
							<view class="box-tab-key">性别</view>
						</view>
					</view>
				</view>
			</view>
			
			<view class='archive' >
				<view class='list-item'  v-for='(item,index) in list' :key='item.id'>
					<view class="title">{{item.title}}</view>
					<view class="user ">
						<image class='icon' src='/static/icon/user.png'></image>
						<view class='name text-cut'>档案确认方: {{item.confirmBy}}</view>
					</view>
					<view class='des'>对方确认以上信息，并对不实信息承担相关责任</view>
					<textItem :itemId='index' :content='item.content'></textItem>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getCargoDetail} from '@/api/pet/index/saler'
	import {listRecord_base} from '@/api/pet/archive/base'
	
	import textItem from './text-item'
	export default {
		components: {
			textItem
		},
		data() {
			return {
				isNull: false,
				searchVal: '',
				cargoDetail: {},
				list: []
			}
		},
		methods: {
			handleSearch() {
				if(!this.searchVal) return uni.showToast({title: '请输入宠物认证编号'})
				this.list = []
				getCargoDetail({
					cargoNo: this.searchVal
				}).then(res => {
					this.isNull = false
					this.cargoDetail = res || {}
					
					listRecord_base({
						cargoId: this.cargoDetail.id
					}).then(res => {
						this.list = res
					})
					
				}).catch(() => {
					this.isNull = true
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		background: linear-gradient( 180deg, #FFFFFF 0%, #F8F8F8 100%);
		
		.search-content {
			padding: 0 24rpx 24rpx 24rpx;
			background-color: #fff;
			
			.search-input {
				width: 100%;
				height: 76rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #F8F8F8;
				border-radius: 40rpx;
				
				.icon {
					width: 40rpx;
					height: 40rpx;
					margin-left: 16rpx;
					margin-right: 8rpx;
				}
				
				input {
					flex: 1;
					height: 100%;
				}
				
				.btn {
					padding: 0 32rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: var(--btnColor);
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}
	
	.data-null {
		margin-top: 300rpx;
		display: flex;
		flex-direction: column;
		display: flex;
		align-items: center;
		
		.img {
			width: 240rpx;
			height: 240rpx;
		}
		
		.text {
			margin-top: 24rpx;
			font-size: 28rpx;
			color: var(--h4Color);
			line-height: 40rpx;
		}
	}
	
	.info-box {
		padding: 0 16rpx;
	}
	
	.head {
		width: 100%;
		margin: 12rpx auto 0;
		position: relative;
		// background: #FFFFFF;
		border-radius: 24rpx;
	
	
		.box {
			width: 100%;
			background: var(--primaryGradBg);
			border-radius: 24rpx;
			padding: 28rpx 28rpx 40rpx;
			box-sizing: border-box;
	
			.user {
				display: flex;
				align-items: center;
				margin-bottom: 48rpx;
	
				.picture {
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
					background: var(--primaryBg);
					margin-right: 17rpx;
				}
	
				.user-content {
					flex: 1;
	
					.user-head {
						width: 100%;
						display: flex;
						align-items: center;
						margin-bottom: 4rpx;
	
						.user-head-name {
							max-width: 350rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 600;
							font-size: 36rpx;
							color: var(--h1Color);
							line-height: 50rpx;
						}
						
						.status {
							width: 154rpx;
							height: 36rpx;
							margin-left: 8rpx;
						}
					}
	
					.user-id {
						background: var(--primaryBg);
						border-radius: 21rpx;
						padding: 0 16rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: var(--h1Color);
						line-height: 40rpx;
						width: max-content;
					}
				}
			}
	
			.box-tab {
				width: 100%;
				height: 80rpx;
				display: flex;
	
				.box-tab-item {
					width: 33.33%;
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					border-right: 1rpx solid var(--primaryBg);
	
					&:last-child {
						border-right: none;
					}
	
					.box-tab-value {
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						font-size: 30rpx;
						color: var(--h1Color);
						line-height: 42rpx;
					}
	
					.box-tab-key {
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 22rpx;
						color: #85773A;
						line-height: 30rpx;
						margin-top: 8rpx;
					}
				}
			}
		}
	}
	
	.archive {
		margin-top: 16rpx;
		
		.list-item {
			width: 100%;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 28rpx 24rpx;
			margin-bottom: 16rpx;
			
			.title {
				font-weight: 600;
				font-size: 34rpx;
				color: var(--h1Color);
				line-height: 48rpx;
			}
			
			.user {
				margin-top: 16rpx;
				display: flex;
				align-items: center;
				line-height: 1;
				color: var(--h2Color);
				
				.icon {
					width: 26rpx;
					height: 26rpx;
					margin-right: 12rpx;
				}
				
				.name {
					max-width: 600rpx;
				}
			}
			
			.des {
				margin-top: 6rpx;
				font-size: 22rpx;
				color: var(--h4Color);
			}
			
		}
	}
</style>